﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ivan.Dm.ChromeRemoteDebugger.Transport;
using System.Net;
using Ivan.Dm.ChromeRemoteDebugger.Protocol;

namespace Ivan.Dm.ChromeRemoteDebuggerSpike {
    class Program {




        public class TestListener : IConnectionStateListener {
            #region IRemoteConnectionListener Members

            public void ConnectionEstablished() {
                DevToolsServiceListTabsRequest command = new DevToolsServiceListTabsRequest();
                Message message = MessageFactory.CreateMessage<DevToolsServiceListTabsRequest>(command);
                Connection.Current.SendMessage(message);
            }

            public void ConnectionTerminated(ConnectionTerminationReason reason) {
                Console.WriteLine("Terminated");
            }

            #endregion
        }

        class MsgListener : IMessageListener {
            #region IMessageListener Members

            public void MessageReceived(Message message) {
                Console.WriteLine(message.Content);
            }

            public void MailformedMessageReceived() {
            }

            #endregion
        }


        static void Main(string[] args) {
            IPEndPoint e = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9222);
            DevToolsServicePingRequest pingCommand = new DevToolsServicePingRequest();
            Message ping = MessageFactory.CreateMessage<DevToolsServicePingRequest>(pingCommand);
            Connection.Current.Establish(e, new TestListener(), new MsgListener(), ping);
            while (true) { }
        }
    }
}
